Imports System.Data.OracleClient

Public Class frmColumnNameAbbreviation

  Public mStrColumnName As String
  Public mIntVrblId As Integer
  Public mStrDataCatg As String
  Public mBlnIsLoaded As Boolean = False
  Private mObjCommand As OracleCommand
  Private mObjDataReader As OracleDataReader
  Private mArrAbbreviationList As New ArrayList
  Private mArrExistColList As New ArrayList
  Public mBlnFormClosed As Boolean = True
  Public mStrTableName As String



  Private Sub frmColumnNameAbbreviation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim lStrQuery As String = ""
    Dim lIntCount As Integer = 0
    Dim lObjClsListBoxProperties As clsMemberProperties

    mPrRefreshConn()
    If mBlnIsLoaded = False Then

      lStrQuery = "Select Distinct TAV_CLMN_DSCRPTN, TAV_SERIAL_NMBR, TAV_DATA_CTGRY, TDCM_DESC"
      lStrQuery = lStrQuery + " from TRDX_DATA_CATEGORY_MSTR,TRDX_APLCTN_VRBLS where TAV_DATA_CTGRY = TDCM_DATA_CTGRY ORDER BY TAV_CLMN_DSCRPTN ASC"

      mObjCommand = New OracleCommand(lStrQuery, con)
      mObjDataReader = mObjCommand.ExecuteReader

      While mObjDataReader.Read
        lObjClsListBoxProperties = New clsMemberProperties
        lObjClsListBoxProperties.mPrpDisplayMember = UCase(mObjDataReader("TAV_CLMN_DSCRPTN"))
        lObjClsListBoxProperties.mPrpValueMember = UCase(mObjDataReader("TAV_SERIAL_NMBR"))
        lObjClsListBoxProperties.mPrpDataCatg = UCase(mObjDataReader("TDCM_DESC"))
        mArrAbbreviationList.Add(lObjClsListBoxProperties)
      End While

      For lIntCount = 0 To mArrAbbreviationList.Count - 1
        lstAbbreviationList.Items.Add(mArrAbbreviationList.Item(lIntCount))
      Next

      lstAbbreviationList.DisplayMember = "mPrpDisplayMember"
      lstAbbreviationList.ValueMember = "mPrpValueMember"


      mBlnIsLoaded = True

      lstAbbreviationList.Focus()
      lstAbbreviationList.SetSelected(0, True)

    End If

  End Sub


  Public Sub mPrLoadExistedCol _
              (ByVal aTableName As String _
              , ByVal aIntTableId As Integer)

    Dim lStrQuery As String = ""
    Dim lIntCount As Integer = 0
    Dim lObjClsListBoxProperties As clsMemberProperties

    lstCols.Items.Clear()
    mArrExistColList.Clear()

    lStrQuery = "Select Distinct TAV_CLMN_DSCRPTN, TAV_SERIAL_NMBR, TAV_DATA_CTGRY, TDCM_DESC,TAB_COL_NULL_INDC,TAB_COL_ID"
    lStrQuery = lStrQuery + " from TRDX_DATA_CATEGORY_MSTR,TRDX_APLCTN_VRBLS, TRDX_TABLE_COLUMNS, TRDX_TABLES_MSTR "
    lStrQuery = lStrQuery + " where TAV_DATA_CTGRY = TDCM_DATA_CTGRY and   TAV_SERIAL_NMBR  = TAB_VRBL_SERIAL_NMBR  "
    lStrQuery = lStrQuery + " and TAB_TABLE_ID = TABM_TABLE_ID and  tabm_table_name='" + aTableName + "'"
    lStrQuery = lStrQuery & " And TABM_TABLE_ID = " & aIntTableId
    lStrQuery = lStrQuery + " Order by TAB_COL_ID "

    mObjCommand = New OracleCommand(lStrQuery, con)
    mObjDataReader = mObjCommand.ExecuteReader

    While mObjDataReader.Read
      lObjClsListBoxProperties = New clsMemberProperties
      lObjClsListBoxProperties.mPrpDisplayMember = UCase(mObjDataReader("TAV_CLMN_DSCRPTN"))
      lObjClsListBoxProperties.mPrpValueMember = UCase(mObjDataReader("TAV_SERIAL_NMBR"))
      lObjClsListBoxProperties.mPrpDataCatg = UCase(mObjDataReader("TDCM_DESC"))
      lObjClsListBoxProperties.mprpColNotNull = UCase(mObjDataReader("TAB_COL_NULL_INDC"))

      mArrExistColList.Add(lObjClsListBoxProperties)
    End While

    For lIntCount = 0 To mArrExistColList.Count - 1
      lstCols.Items.Add(mArrExistColList.Item(lIntCount))
    Next

    lstCols.DisplayMember = "mPrpDisplayMember"
    lstCols.ValueMember = "mPrpValueMember"

  End Sub


  Private Sub cmdColumnNameSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColumnNameSelect.Click

    If lstCols.Items.Count > 0 Then
      mBlnIsLoaded = False
      mBlnFormClosed = False
      Me.Close()

    Else
      If MessageBox.Show("No Column Name selected, do you continue?", gCONST_MSG_HEADER, MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
        mBlnIsLoaded = False
        mBlnFormClosed = False
        Me.Close()
        Me.DialogResult = Windows.Forms.DialogResult.Yes
      Else
        Me.DialogResult = Windows.Forms.DialogResult.No
      End If
    End If
  End Sub





  Public Sub New()

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    mStrColumnName = ""

  End Sub




  Private Sub frmColumnNameAbbreviation_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
    If Me.Visible = True Then
      lstAbbreviationList.Focus()
      lstAbbreviationList.SetSelected(0, True)
    End If
  End Sub






  Private Sub lstAbbreviationList_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstAbbreviationList.MouseDoubleClick

  End Sub

  Private Sub cmdSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSelect.Click
    Dim lStrCol As String
    Dim lBlnExist As Boolean = False
    Dim lIntIndex As Integer

    lStrCol = lstAbbreviationList.SelectedItem.mprpDisplayMember

    If lstAbbreviationList.Items.Count > 0 Then

      For lIntIndex = 0 To lstCols.Items.Count - 1
        If lstCols.Items.Item(lIntIndex).mprpDisplayMember = lStrCol Then
          lBlnExist = True
        End If
      Next

      If Not lBlnExist Then
        'lstCols.Items.Add(lStrCol)
        lstCols.Items.Add(lstAbbreviationList.SelectedItem)

        lstCols.DisplayMember = "mPrpDisplayMember"
        lstCols.ValueMember = "mPrpValueMember"

      End If

    End If
  End Sub

  Private Sub cmdDeSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDeSelect.Click
    If lstCols.Items.Count > 0 Then
      lstCols.Items.Remove(lstCols.SelectedItem)
    End If
  End Sub

  Private Sub cmdDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDown.Click
    Try
      Dim lIntSelectedIndex As Integer

      If lstCols.SelectedIndex >= 0 And lstCols.SelectedIndex <> lstCols.Items.Count - 1 Then
        lIntSelectedIndex = lstCols.SelectedIndex
        lstCols.Items.Insert(lstCols.SelectedIndex + 2, lstCols.SelectedItem)
        lstCols.Items.RemoveAt(lstCols.SelectedIndex)
        If (lIntSelectedIndex + 2) >= lstCols.Items.Count Then
          lIntSelectedIndex = lstCols.Items.Count - 1
        Else
          lIntSelectedIndex = lIntSelectedIndex + 1
        End If

        lstCols.Focus()
        lstCols.SetSelected(lIntSelectedIndex, True)
      End If

    Finally
    End Try
  End Sub

  Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click
    Try
      Dim lIntSelectedIndex As Integer

      If lstCols.SelectedIndex > 0 Then
        lIntSelectedIndex = lstCols.SelectedIndex
        lstCols.Items.Insert(lstCols.SelectedIndex - 1, lstCols.SelectedItem)
        lstCols.Items.RemoveAt(lstCols.SelectedIndex)
        lstCols.Focus()
        lstCols.SetSelected(lIntSelectedIndex - 1, True)
      End If

    Finally
    End Try
  End Sub

  Private Sub cmdDeSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDeSelectAll.Click
    lstCols.Items.Clear()
  End Sub

  Private Sub cmdSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSelectAll.Click
    Dim lBlnExist As Boolean = False
    Dim lIntIndex As Integer

    lstCols.Items.Clear()

    If lstAbbreviationList.Items.Count > 0 Then
      For lIntIndex = 0 To lstAbbreviationList.Items.Count - 1
        lstAbbreviationList.SetSelected(lIntIndex, True)
        'lStrCol = lstAbbreviationList.SelectedItem.mprpDisplayMember
        'lstCols.Items.Add(lStrCol)

        lstCols.Items.Add(lstAbbreviationList.SelectedItem)

        lstCols.DisplayMember = "mPrpDisplayMember"
        lstCols.ValueMember = "mPrpValueMember"
      Next
    End If
  End Sub
End Class